<style lang="scss">
  @import "../../../../assets/css/_variable";

  .xy-header {
    background-color: $color-khan-blue;
    height: 60px;
    width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .xy-header .logo {
    margin-left: 1em;
  }

  .xy-header .menu {
    margin-right: 1em;
  }
</style>
<template>
  <div>
    <div class="xy-header">
      <div class="logo" @click="goToWelcome()">
        <span class="color-white">17</span>
        <span class="color-white">小学</span>
      </div>
      <div class="menu">
        <span v-if="!loginName" @click="goLogin()" class="color-white margin-right-normal">登录</span>
        <span class="color-white margin-right-normal" v-else>{{loginName}}</span>
        <span class="color-white" @click="menuVisible=true"><i class="el-icon-menu"></i></span>
      </div>
    </div>

    <el-dialog
      title=""
      :visible.sync="dialogVisible"
      size="full">
      <el-input v-model="username">
        <template slot="prepend">用户名</template>
      </el-input>
      <el-input v-model="password">
        <template slot="prepend">密码</template>
      </el-input>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="login()">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog
      :visible.sync="menuVisible"
      size="full">
    </el-dialog>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        menuVisible: false,
        username: '610S201503001',
        password: '123456',
        loginName: ''
      }
    },
    computed: {},
    methods: {
      goToWelcome() {
        if (this.$store.state.app.currentUser.token) {
          //跳转
          this.$router.push({name: '我'});
        } else {
          this.$router.push({name: '欢迎页'});
        }
      },
      goLogin() {
        this.dialogVisible = true;
      },
      login() {
        let url = this.$store.state.app.api.passport + 'login/doLogon';
        let username = this.username;
        let password = this.password;
        this.$store.dispatch('app/login', {
          username,
          password,
          callback: (success, msg) => {
            if (success) {
              debugger;
              this.dialogVisible = false;
              this.$message({
                message: '登录成功',
                type: 'success'
              });
              this.loginName = this.$store.state.app.currentUser.name;
              global_token = this.$store.state.app.currentUser.token;
              global_student = this.$store.state.app.currentUser.id;
            } else {
              this.$message.error(msg);
            }
          }
        });
      },
      logout() {

      }
    },
    mounted() {
      this.loginName = this.$store.state.app.currentUser.name;
    }
  }
</script>
